<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\User as usersmodel;
return new class extends Migration {
    //用户表
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('users', function (Blueprint $table) {
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
            $table->id();
            $table->string('userid', 30)->unique();
            $table->string('name', 50);
            $table->string('tel', 20)->unique();
            $table->string('password', 200);
            $table->string('employeeid', 30)->nullable();
            $table->string('channelid', 50)->nullable();
            //$table->string('usrgroupids', 200)->nullable();
            $table->string('providerid', 50)->nullable();
            $table->string('customerid', 50)->nullable();
            $table->string('des', 200)->nullable();
            $table->integer('synstate')->nullable();
            $table->timestamp('syndate')->nullable();
            $table->integer('isdel')->nullable()->default(0);
            $table->integer('state')->nullable()->default(1);
            $table->string('modifier', 50)->nullable();
            $table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
            $table->timestamp('created_at')->nullable();
        });
        //用户所属角色
        Schema::create('userrole', function (Blueprint $table) {
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
            $table->id();
            $table->string('userid', 50);
            $table->string('roleid', 50);
            $table->string('des', 200)->nullable();
            $table->integer('isdel')->nullable()->default(0);
            $table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
            $table->timestamp('created_at')->nullable();
        });

        // 插入单个数据
        usersmodel::create([
            'userid' => '000000',
            'name' => 'admin',
            'tel' => '00000000000',
            'channelid' => '000',
            'des' => '系统管理员',
            'password' => Hash::make(123456),
        ]);
        DB::table('userrole')->insert(['userid' => 1, 'roleid' => 1]);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('users');
        Schema::dropIfExists('userrole');
    }
};
